// FacebookHyperLinkDesigner.cs
// Facebook/FrameworkWeb/Design/Web/IFrame
// Copyright (c) 2007, Nikhil Kothari. All Rights Reserved.
//

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Web;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
using Facebook.Web.IFrame;

namespace Facebook.Design.Web.IFrame {

    /// <summary>
    /// The designer associated with a FacebookHyperLink control.
    /// </summary>
    public class FacebookHyperLinkDesigner : ControlDesigner {

        /// <summary>
        /// Gets the design-time HTML used to render the control on the design surface.
        /// </summary>
        /// <returns>The appropriate design-time HTML.</returns>
        public override string GetDesignTimeHtml() {
            FacebookHyperLink h = (FacebookHyperLink)Component;

            string originalText = h.Text;
            string imageUrl = h.ImageUrl;
            string originalUrl = h.NavigateUrl;

            bool blankText = (originalText.Trim().Length == 0) && (imageUrl.Trim().Length == 0);
            bool blankUrl = (originalUrl.Trim().Length == 0);

            if (blankText) {
                h.Text = "[" + h.ID + "]";
            }
            if (blankUrl) {
                h.NavigateUrl = "url";
            }

            string html;
            try {
                html = base.GetDesignTimeHtml();
            }
            finally {
                if (blankText) {
                    h.Text = originalText;
                }
                if (blankUrl) {
                    h.NavigateUrl = originalUrl;
                }
            }
            return html;
        }

        /// <summary>
        /// Initalizes an instance of a FacebookHyperLinkDesigner with its associated
        /// component.
        /// </summary>
        /// <param name="component">The associated component.</param>
        public override void Initialize(IComponent component) {
            if (!(component is FacebookHyperLink)) {
                throw new ArgumentOutOfRangeException("component");
            }

            base.Initialize(component);
        }
    }
}
